<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='global-property-S-'>/**
</span> * @fileOverview 输入提示信息
 * @author dxq613@gmail.com
 * @ignore
 */


var $ = require(&#39;jquery&#39;),
  BUI = require(&#39;bui-common&#39;),
  prefix = BUI.prefix,
  Overlay = require(&#39;bui-overlay&#39;).Overlay,
  FIELD_TIP = &#39;data-tip&#39;,
  CLS_TIP_CONTAINER = prefix + &#39;form-tip-container&#39;;

<span id='BUI-Form-TipItem'>/**
</span> * 表单提示信息类
 * xclass:&#39;form-tip&#39;
 * @class BUI.Form.TipItem
 * @extends BUI.Overlay.Overlay
 */
var tipItem = Overlay.extend(

{
  initializer : function(){
    var _self = this,
      render = _self.get(&#39;render&#39;);
    if(!render){
      var parent = $(_self.get(&#39;trigger&#39;)).parent();
      _self.set(&#39;render&#39;,parent);
    }
  },
  renderUI : function(){
    var _self = this;

    _self.resetVisible();
    
  },
<span id='BUI-Form-TipItem-method-resetVisible'>  /**
</span>   * 重置是否显示
   */
  resetVisible : function(){
    var _self = this,
      triggerEl = $(_self.get(&#39;trigger&#39;));

    if(triggerEl.val()){//如果默认有文本则不显示，否则显示
      _self.set(&#39;visible&#39;,false);
    }else{
      _self.set(&#39;align&#39;,{
        node:$(_self.get(&#39;trigger&#39;)),
        points: [&#39;cl&#39;,&#39;cl&#39;]
      });
      _self.set(&#39;visible&#39;,true);
    }
  },
  bindUI : function(){
    var _self = this,
      triggerEl = $(_self.get(&#39;trigger&#39;));

    _self.get(&#39;el&#39;).on(&#39;click&#39;,function(){
      _self.hide();
      triggerEl.focus();
    });
    triggerEl.on(&#39;click focus&#39;,function(){
      _self.hide();
    });

    triggerEl.on(&#39;blur&#39;,function(){
      _self.resetVisible();
    });
  }
},{
  ATTRS : 
  {
<span id='BUI-Form-TipItem-cfg-trigger'>    /**
</span>     * 提示的输入框 
     * @cfg {String|HTMLElement|jQuery} trigger
     */
<span id='BUI-Form-TipItem-property-trigger'>    /**
</span>     * 提示的输入框
     * @type {String|HTMLElement|jQuery}
     */
    trigger:{

    },
<span id='BUI-Form-TipItem-cfg-text'>    /**
</span>     * 提示文本
     * @cfg {String} text
     */
<span id='BUI-Form-TipItem-property-text'>    /**
</span>     * 提示文本
     * @type {String}
     */
    text : {

    },
<span id='BUI-Form-TipItem-cfg-iconCls'>    /**
</span>     * 提示文本上显示的icon样式
     * @cfg {String} iconCls
     *     iconCls : icon-ok
     */
<span id='BUI-Form-TipItem-property-iconCls'>    /**
</span>     * 提示文本上显示的icon样式
     * @type {String}
     *     iconCls : icon-ok
     */
    iconCls:{

    },
<span id='BUI-Form-TipItem-property-tpl'>    /**
</span>     * 默认的模版
     * @type {String}
     * @default &#39;&lt;span class=&quot;{iconCls}&quot;&gt;&lt;/span&gt;&lt;span class=&quot;tip-text&quot;&gt;{text}&lt;/span&gt;&#39;
     */
    tpl:{
      value:&#39;&lt;span class=&quot;{iconCls}&quot;&gt;&lt;/span&gt;&lt;span class=&quot;tip-text&quot;&gt;{text}&lt;/span&gt;&#39;
    }
  }
},{
  xclass : &#39;form-tip&#39;
});

<span id='BUI-Form-Tips'>/**
</span> * 表单提示信息的管理类
 * @class BUI.Form.Tips
 * @extends BUI.Base
 */
var Tips = function(config){
  if (this.constructor !== Tips){
    return new Tips(config);
  }

  Tips.superclass.constructor.call(this,config);
  this._init();
};

Tips.ATTRS = 
{

<span id='BUI-Form-Tips-cfg-form'>  /**
</span>   * 表单的选择器
   * @cfg {String|HTMLElement|jQuery} form
   */
<span id='BUI-Form-Tips-property-form'>  /**
</span>   * 表单的选择器
   * @type {String|HTMLElement|jQuery}
   */
  form : {

  },
<span id='BUI-Form-Tips-property-items'>  /**
</span>   * 表单提示项对象 {@link BUI.Form.TipItem}
   * @readOnly
   * @type {Array} 
   */
  items : {
    valueFn:function(){
      return [];
    }
  }
};

BUI.extend(Tips,BUI.Base);

BUI.augment(Tips,{
  _init : function(){
    var _self = this,
      form = $(_self.get(&#39;form&#39;));
    if(form.length){
      BUI.each($.makeArray(form[0].elements),function(elem){
        var tipConfig = $(elem).attr(FIELD_TIP);
        if(tipConfig){
          _self._initFormElement(elem,$.parseJSON(tipConfig));
        }
      });
      form.addClass(CLS_TIP_CONTAINER);
    }
  },
  _initFormElement : function(element,config){
    if(config){
      config.trigger = element;
      //config.render = this.get(&#39;form&#39;);
    }
    var _self = this,
      items = _self.get(&#39;items&#39;),
      item = new tipItem(config);
    items.push(item);
  },
<span id='BUI-Form-Tips-method-getItem'>  /**
</span>   * 获取提示项
   * @param {String} name 字段的名称
   * @return {BUI.Form.TipItem} 提示项
   */
  getItem : function(name){
    var _self = this,
      items = _self.get(&#39;items&#39;),
      result = null;
    BUI.each(items,function(item){

      if($(item.get(&#39;trigger&#39;)).attr(&#39;name&#39;) === name){
        result = item;
        return false;
      }

    });

    return result;
  },
<span id='BUI-Form-Tips-method-resetVisible'>  /**
</span>   * 重置所有提示的可视状态
   */
  resetVisible : function(){
    var _self = this,
      items = _self.get(&#39;items&#39;);

    BUI.each(items,function(item){
      item.resetVisible();
    });
  },
<span id='BUI-Form-Tips-method-render'>  /**
</span>   * 生成 表单提示
   */
  render:function(){
     var _self = this,
      items = _self.get(&#39;items&#39;);
    BUI.each(items,function(item){
      item.render();
    });
  },
<span id='BUI-Form-Tips-method-destroy'>  /**
</span>   * 删除所有提示
   */
  destroy:function(){
    var _self = this,
      items = _self.get(items);

    BUI.each(items,function(item){
      item.destroy();
    });
  }
});

Tips.Item = tipItem;

module.exports = Tips;
</pre>
</body>
</html>
